<?php




require_once 'gpxReader.php';
// $filename = 'Slad_03-LIP-13213618.gpx';
// $filename = 'Slad_12-LIP-13 150758.gpx';
$filename = 'Slad_14-LIP-13 145945.gpx';
// $filename = '2sladyW1.gpx';
$gpx = simplexml_load_file($filename);

$tripObj = new distanceFromGpx($gpx);
$tripObj->calculate();
$result = $tripObj->getTrip();
$googleMapArr = $tripObj->extractData4googleMapsPolilyne();


foreach ($googleMapArr as $trackId => $track) {
	$i = 1;
	$polilyne[$i] = null;
	$polilyneOld[$i] = null;
	foreach ($track as $pointId=> $point) {
		//var_dump($point); exit;
		$polilyneOld[$i] .= 'new google.maps.LatLng('.$point['lat'].', '.$point['lon'].'),';
		$polilyne[$i] .= "[".$point['lat'].",".$point['lon']."],";
		
	}
	$i++;
}

print 'roznica wysokości w metrach (w gore): '.$result->upHill.'<br>';
print 'roznica wysokości w metrach (w dol): '.$result->downHill.'<br>';
print 'dlugosc trasy (km): '.$result->distance.'<br>';
print 'czas ruchu (hh:mm:ss): '.$result->movingTime .'<br>';
print 'czas postoju (hh:mm:ss): '.$result->stopTime.'<br>';
print 'predkosc srednia ruchu (km/h): '.$result->avgSpeed.'<br>';
print 'max predkosc chwilowa (km/h): '.$result->maxSpeed.'<br>';

?>
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Simple Polylines</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>





function initialize() {

var ptMapCenterLat = 50;
var ptMapCenterLon = 20;
var mapZoom = 5;
var fullCountryMap = 0;
var caches = [ <?php print $polilyne[1]; ?> ];
//var caches = [ [54.0355795529,23.3584900293],[54.0356571693,23.3583129197],[54.0357076284,23.3582527377],[54.0359902661,23.358161794],[54.0369288716,23.3575722948],];

//osm
var mapTypeIds = [];
for(var type in google.maps.MapTypeId) {
    mapTypeIds.push(google.maps.MapTypeId[type]);
}
mapTypeIds.push("OSM");
mapTypeIds.push("UMP");

//end osm

var myLatlng = new google.maps.LatLng(ptMapCenterLat, ptMapCenterLon);
var mapOptions = {
    zoom: mapZoom,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControlOptions: {
        mapTypeIds: mapTypeIds
    }
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var bounds = new google.maps.LatLngBounds(); 

map.mapTypes.set("OSM", new google.maps.ImageMapType({
                getTileUrl: function(coord, zoom) {
                    return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png";
                },
                tileSize: new google.maps.Size(256, 256),
                name: "OSM",
                maxZoom: 18
}));
map.mapTypes.set("UMP", new google.maps.ImageMapType({
                getTileUrl: function(coord, zoom) {
                    return "http://1.tiles.ump.waw.pl/ump_tiles/" + zoom + "/" + coord.x + "/" + coord.y + ".png";
                },
                tileSize: new google.maps.Size(256, 256),
                name: "UMP",
                maxZoom: 18
}));

var flightPlanCoordinates = new Array();
var i = 0;
var bounds = new google.maps.LatLngBounds();
caches.forEach(function(entry) {
    flightPlanCoordinates[i] = new google.maps.LatLng(entry[0],entry[1]);
    //bounds.extend(entry[0],entry[1]);
    i++;
});

  var flightPath = new google.maps.Polyline({
    //path: flightPlanCoordinates,
    path: flightPlanCoordinates,
    geodesic: true,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2
  });

  flightPath.setMap(map);
  
var latlngbounds = new google.maps.LatLngBounds();
for (var i = 0; i < flightPlanCoordinates.length; i++) {
	for (var j = 0; j < flightPlanCoordinates[i].length; j++) {
		latlngbounds.extend(flightPlanCoordinates[i][j]);
	}
}
map.setCenter(latlngbounds.getCenter(), map.getBoundsZoomLevel(latlngbounds));



}
google.maps.event.addDomListener(window, 'load', initialize);
/* maps end */

</script>
  </head>
  <body>
    <div id="map-canvas" style="width: 700px; height: 500px;"></div>
  </body>
</html>